package com.practice.config;

import cn.hutool.crypto.SecureUtil;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class CustomTypeHandler<T> extends BaseTypeHandler<T> {
    @Override
    public void setNonNullParameter(PreparedStatement ps, int i, T t, JdbcType jdbcType) throws SQLException {
        ps.setString(i, SecureUtil.md5((String) t));
    }

    @Override
    public T getNullableResult(ResultSet rs, String s) throws SQLException {
        return (T)rs.getObject(s);
    }

    @Override
    public T getNullableResult(ResultSet rs, int i) throws SQLException {
        return (T)rs.getObject(i);
    }

    @Override
    public T getNullableResult(CallableStatement cs, int i) throws SQLException {
        return (T)cs.getObject(i);
    }
}
